<?php
/**********************************************************
** Lime Manager
** Thomas Knobloch & Clément Troesch
** Manager Rights Ajax View
***********************************************************/
?>

<?php session_start(); ?>
<?php include_once "../../model/ReferentialConnectionModel.php"; ?>
<?php include_once "../../model/StatisticModel.php"; ?>

<?php
	$nbJour = 5;
	if(isset($_GET['nbJour']))
	{
		$nbJour = $_GET['nbJour'];
	}
?>

<div class="section_title"><h1> Statistiques </h1></div>
<div class="section_info">
	Statistiques des connections
</div>

<div class="article">
	Nombre de jours:
	<input type="number" value="<?php echo $nbJour ?>" id="nbJour" />
	<input type="button" value="Valider" onClick="displayStatistics($('#nbJour').val())" />
	<br /><br />
	<div id="chart_div" class="chart"></div>
	<br /><br />
	<div id="chart_div2" class="chart"></div>
</div>


<br /><br />

<script type="text/javascript">
	google.load("visualization", "1", {packages:["corechart"]});
	google.setOnLoadCallback(drawChart);
	function drawChart() {
		var data = google.visualization.arrayToDataTable([
			['Utilisateur', 'Nombre de connexions'],
			<?php
				StatisticModel::getNumberOfConnectionsPerUsers($nbJour,$result);
				foreach($result as $row)
				{
					echo "['".$row['LOGIN']."', ".$row['COUNT(*)']."],";
				}
			?>
		]);

	var options = {
		title: 'Nombre de connexions dans les <?php echo $nbJour ?> derniers jours.',
		hAxis: {title: 'Utilisateur', titleTextStyle: {color: 'red'}},
		backgroundColor:{
			fill: '#eff3fc'
		},
		width: 800,
		height:400
	};

	var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
		chart.draw(data, options);
	}

</script>




<script type="text/javascript">
	google.load("visualization", "1", {packages:["corechart"]});
	google.setOnLoadCallback(drawChart2);
	function drawChart2() {
		var data2 = google.visualization.arrayToDataTable([
			['Jour', 'Nombre de connexions'],
		  <?php
				StatisticModel::getNumberOfConnectionsPerDay($nbJour,$result);
				foreach($result as $row)
				{
					echo "['".$row["TO_CHAR(C.CONNECTION_TIME,'MM/DD/YY')"]."', ".$row['COUNT(*)']."],";
				}
			?>
		]);

	var options2 = {
		title: 'Nombre de connexions / jours durant les <?php echo $nbJour ?> derniers jours',
		backgroundColor:{
			fill: '#eff3fc'
		},
		width: 800,
		height:400
	};

	var chart2 = new google.visualization.LineChart(document.getElementById('chart_div2'));
		chart2.draw(data2, options2);
	}
</script>


<script type="text/javascript">
	//JQuery main entry point
	$(document).ready(function() {
		drawChart();
		drawChart2();
	});
</script>